//
//  MyJourneyMainCell.m
//  didihaha
//
//  Created by 赵忠鹏 on 2017/8/3.
//  Copyright © 2017年 zhaozhongpeng. All rights reserved.
//

#import "MyJourneyMainCell.h"
#import "Masonry.h"
#import "MyJourneyTextFild.h"

@interface MyJourneyMainCell ()

@property (nonatomic,strong)UIView *bgView;

/**
 火箭类型
 */
@property (nonatomic,strong)MyJourneyTextFild *taxiTypeTextField;

/**
 订单类型
 */
@property (nonatomic,strong)MyJourneyTextFild *orderTypeTextField;

/**
 订单时间
 */
@property (nonatomic,strong)MyJourneyTextFild *orderTimeTextField;

/**
 老司机上车
 */
@property (nonatomic,strong)MyJourneyTextFild *getOnTextField;


/**
 老司机下车
 */
@property (nonatomic,strong)MyJourneyTextFild *getOffTextField;

/**
 右边的箭头
 */
@property (nonatomic, strong)UIImageView *rightArrow;

/**
 订单时间
 */
@property (nonatomic, strong)UIImageView *oderTimeImageView;

/**
 上车状态
 */
@property (nonatomic, strong)UIImageView *getOnImageView;

/**
 下车状态
 */
@property (nonatomic, strong)UIImageView *getOffImageView;



@end


@implementation MyJourneyMainCell



+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"MessageTableViewCell";
    
    MyJourneyMainCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[MyJourneyMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor colorWithRed:240/255.0 green:241/255.0 blue:242/255.0 alpha:1];
        [self createUI];
    }
    return  self;
}

- (void)createUI{
    
    [self.contentView addSubview:self.bgView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    
    [self.bgView addSubview:self.taxiTypeTextField];// 火箭
    [self.bgView addSubview:self.orderTypeTextField];// 订单类型
    [self.bgView addSubview:self.orderTimeTextField];// 订单时间
    [self.bgView addSubview:self.getOnTextField];// 上车
    [self.bgView addSubview:self.getOffTextField];// 下车
    [self.bgView addSubview:self.rightArrow]; // 右边箭头
    [self.bgView addSubview:self.oderTimeImageView];// 订单时间图片
    [self.bgView addSubview:self.getOnImageView];//上车
    [self.bgView addSubview:self.getOffImageView];//下车
    
    // 火箭
    [self.taxiTypeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(20);
        make.top.equalTo(self.bgView.mas_top).offset(20);
        make.width.mas_equalTo(280);
        make.height.mas_equalTo(13);
    }];
    
    // 订单状态
    [self.orderTypeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-28);
        make.top.height.equalTo(self.taxiTypeTextField);
        make.width.mas_equalTo(50);
    }];
    
    NSInteger space = 12;
    // 订单时间
    [self.orderTimeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(35);
        make.top.equalTo(self.taxiTypeTextField.mas_bottom).offset(space);
        make.width.height.equalTo(self.taxiTypeTextField);
    }];
    
   // 老司机开车
    [self.getOnTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.equalTo(self.orderTimeTextField);
        make.top.equalTo(self.orderTimeTextField.mas_bottom).offset(space);
    }];
    
    // 老司机下车
    [self.getOffTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.width.equalTo(self.orderTimeTextField);
        make.top.equalTo(self.getOnTextField.mas_bottom).offset(space);
    }];
    
    
    // 右边箭头
    [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.orderTypeTextField.mas_right).offset(15);
        make.centerY.equalTo(self.orderTypeTextField.mas_centerY);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(10);
    }];
    
    [self.oderTimeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.orderTimeTextField.mas_centerY);
        make.centerX.equalTo(self.taxiTypeTextField.mas_left);
        make.height.width.mas_equalTo(7);
    }];
    
    NSInteger imageWith = 5;
    [self.getOnImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.getOnTextField.mas_centerY);
        make.centerX.equalTo(self.oderTimeImageView.mas_centerX);
        make.height.width.mas_equalTo(imageWith);
    }];
    
    [self.getOffImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.getOffTextField.mas_centerY);
        make.centerX.equalTo(self.oderTimeImageView.mas_centerX);
        make.height.width.mas_equalTo(imageWith);
    }];
    
    
    
}
#pragma mark - 懒加载
// 火箭类型
- (MyJourneyTextFild *)taxiTypeTextField{
    if (_taxiTypeTextField == nil) {
        _taxiTypeTextField = [[MyJourneyTextFild alloc] init];
        _taxiTypeTextField.textColor = [UIColor blackColor];
    }
    return _taxiTypeTextField;
}

// 订单类型
- (MyJourneyTextFild *)orderTypeTextField{
    if (_orderTypeTextField == nil) {
        _orderTypeTextField = [[MyJourneyTextFild alloc] init];

    }
    return _orderTypeTextField;
}

// 订单时间
- (MyJourneyTextFild *)orderTimeTextField{
    if (_orderTimeTextField == nil) {
        _orderTimeTextField = [[MyJourneyTextFild alloc] init];
    }
    return _orderTimeTextField;
}

// 老司机上车
- (MyJourneyTextFild *)getOnTextField{
    if (_getOnTextField == nil) {
        _getOnTextField = [[MyJourneyTextFild alloc] init];
    }
    return _getOnTextField;
}

// 老司机下车
- (MyJourneyTextFild *)getOffTextField{
    if (_getOffTextField == nil) {
        _getOffTextField = [[MyJourneyTextFild alloc] init];
    }
    return _getOffTextField;
}

// 右边的箭头
- (UIImageView *)rightArrow{
    if (_rightArrow == nil) {
        _rightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"takecar_bg_map_bubble_arrow"]];
    }
    return _rightArrow;
}

-(UIImageView *)oderTimeImageView{
    if (_oderTimeImageView == nil) {
        _oderTimeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_card_time"]];
    }
    return _oderTimeImageView;
}

- (UIImageView *)getOnImageView{
    if (_getOnImageView == nil) {
        _getOnImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_start"]];
    }
    return _getOnImageView;
}

- (UIImageView *)getOffImageView{
    if (_getOffImageView == nil) {
        _getOffImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_end"]];
    }
    return _getOffImageView;
}


- (UIView *)bgView{
    if (_bgView == nil) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 2;
        _bgView.clipsToBounds = YES;
    }
    return _bgView;
}

#pragma mark - setter

- (void)setModel:(MyJourneyMainModel *)model{
    _model = model;
    
    // 1.
    self.taxiTypeTextField.text = model.TaxiType;
    // 2.
    self.orderTypeTextField.text = model.OrderStauts;
    // 3.
    self.orderTimeTextField.text = model.OrderDate;
    // 4.
    self.getOnTextField.text = model.GetOnAdress;
    // 5.
    self.getOffTextField.text = model.GetOffAdress;
}



@end
